package com.campus.academic.controller;

import com.campus.academic.job.dto.AuditResourcesDTO;
import com.campus.academic.job.dto.LearningResourcesDTO;
import com.campus.academic.job.dto.LearningResourcesUpdateDTO;
import com.campus.academic.job.entity.LearningResources;
import com.campus.academic.job.vo.LearningResourcesListVO;
import com.campus.academic.job.vo.LearningResourcesVO;
import com.campus.academic.service.ILearningResourcesService;
import com.campus.common.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MWB
 */
@RestController
@RequestMapping("/academicLearning")
@Tag(name = "学生资源服务")
public class LearningResourceController {

    @Autowired
    private ILearningResourcesService learningResourcesService;

    @ApiOperation(value = "上传资源")
    @PostMapping()
    public Result<Void> uploadResource(@RequestBody LearningResourcesDTO learningResourcesDTO) {

        learningResourcesService.saveResource(learningResourcesDTO);
        return Result.success();
    }

    @ApiOperation(value = "修改资源")
    @PutMapping()
    public Result<Void> updateResource(@RequestBody LearningResourcesUpdateDTO learningResourcesUpdateDTO) {
        learningResourcesService.updateResource(learningResourcesUpdateDTO);
        return Result.success();
    }


    @ApiOperation(value = "删除资源")
    @DeleteMapping()
    public Result<Void> deleteResource(@RequestParam("id") Integer id) {
        learningResourcesService.deleteResource(id);
        return Result.success();
    }

    @ApiOperation(value = "查询资源详情")
    @GetMapping()
    public Result<LearningResourcesVO> getResource(@RequestParam("id") Integer id) {
        LearningResourcesVO vo = learningResourcesService.getResource(id);
        return Result.success(vo);
    }

    @ApiOperation(value = "获取我的资源列表")
    @GetMapping("/list")
    public Result<List<LearningResourcesListVO>> getResourceList() {
        List<LearningResourcesListVO> list = learningResourcesService.getResourceList();
        return Result.success(list);
    }

    @ApiOperation(value = "资源审核")
    @PostMapping("/audit")
    public Result<Void> auditResource(@RequestBody AuditResourcesDTO auditResourcesDTO) {
        learningResourcesService.auditResource(auditResourcesDTO);
        return Result.success();
    }

    @ApiOperation(value = "获取所有资源列表")
    @GetMapping("/all")
    public Result<List<LearningResourcesVO>> getAllResourceList() {
        List<LearningResourcesVO> list = learningResourcesService.getAllResourceList();
        return Result.success(list);
    }


}
